import nyNetwork from "@/api/nyBaseNetwork";
import DZModelPage from "@/model/DZModelPage";
import dateUtil from "@/utils/DZDateUtil";
import uploadFile from "@/utils/DZUploadFile";
import nyMessageToast from "@/utils/NYMessageToast";
import DZModelDataDic from "../model/DZModelDataDic";
import DZModelExportInfo from "../model/DZModelExportInfo";
import DZModelSubscribe from "../model/DZModelSubscribe";

class DZServiceExport {

    m_page = new DZModelPage(10);

    /**
     * 咨询对象字典
     */
    list_target: Array<DZModelDataDic> = [];

    /**
     * 咨询主题字典
     */
    list_theme: Array<DZModelDataDic> = [];

    /**
     * 擅长疗法字典
     */
    list_field: Array<DZModelDataDic> = [];

    /**
     * 专家列表
     */
    list_export: Array<DZModelExportInfo> = [];

    /**
     * 专家详情
     */
    m_export = new DZModelExportInfo();

    /**
     * 预约记录
     */
    list_subscribe: Array<DZModelSubscribe> = [];

    m_subscribe_screen = { export: '', date: '' }

    net_list_dic() {
        this.list_target = [];
        this.list_theme = [];
        this.list_field = [];
        nyNetwork.net('字典列表', {}, (data: any) => {
            if (data.target) {
                for (let item of data.target) {
                    var target = new DZModelDataDic();
                    target.id = item.iId;
                    target.name = item.sName;
                    this.list_target.push(target);
                }
            }
            if (data.theme) {
                for (let item of data.theme) {
                    var theme = new DZModelDataDic();
                    theme.id = item.iId;
                    theme.name = item.sName;
                    this.list_theme.push(theme);
                }
            }
            if (data.field) {
                for (let item of data.field) {
                    var field = new DZModelDataDic();
                    field.id = item.iId;
                    field.name = item.sName;
                    this.list_field.push(field);
                }
            }
        });
    }

    net_list_theme() {
        var arr_data = [];
        nyNetwork.net('咨询主题', { type: 2 }, (data: any) => {
            for (let item of data) {
                var theme = new DZModelDataDic();
                theme.id = item.iId;
                theme.name = item.sName;
                arr_data.push(theme);
            }
            this.list_theme = arr_data;
        });
    }

    net_list_export() {
        var arr_data = [];
        nyNetwork.net("专家列表", { name: this.m_export.name, ...this.m_page }, data => {
            this.m_page.total = data.total;
            for (const item of data.list) {
                var exportInfo = new DZModelExportInfo();
                exportInfo.id = item.iId ?? '';
                exportInfo.name = item.sName ?? '';
                if (item.iHeard) {
                    exportInfo.heard_url = nyNetwork.image(item.iHeard);
                }
                exportInfo.status = item.iStatus ?? 0;
                exportInfo.frozen = item.iFrozen ?? 0;
                exportInfo.sort = item.iSort ?? 0;
                exportInfo.top = item.iTop ?? 0;
                arr_data.push(exportInfo);
            }
            this.list_export = arr_data;
        });
    }

    net_change_status(id, success: () => void) {
        nyNetwork.net("冻结解冻", { id: id }, data => {
            success();
        });
    }
    net_del_export(id, success: () => void) {
        nyNetwork.net("删除专家", { id: id }, data => {
            success();
        });
    }


    net_info_export() {
        nyNetwork.net("专家详情", { id: this.m_export.id }, data => {
            this.m_export.parse(data);
        });
    }

    net_edit_export(success: () => void) {
        nyNetwork.net("修改专家", { ...this.m_export }, data => {
            success();
        });
    }
    net_edit_sort(id,sort,success: () => void) {
        nyNetwork.net("保存排序", { exportId:id,sort:sort }, data => {
            success();
        });
    }
    net_upload_image(file, success: (data) => void, filed: () => void) {
        uploadFile.uploadImage(file,
            (res) => {
            }, (res) => {
                nyMessageToast.success("图片上传成功")
                success(res + '');
            }, (res) => {
                nyMessageToast.error("图片上传失败")
                filed();
            });
    }

    net_list_export_dic() {
        var arr_data = [];
        nyNetwork.net("专家字典列表", {}, data => {
            for (const item of data) {
                var exportInfo = new DZModelExportInfo();
                exportInfo.id = item.iId ?? '';
                exportInfo.name = item.sName ?? '';
                arr_data.push(exportInfo);
            }
            this.list_export = arr_data;
        })
    }

    net_list_subscribe() {
        var arr_data = [];
        nyNetwork.net("预约列表", { ...this.m_subscribe_screen, ...this.m_page }, data => {
            this.m_page.total = data.total;
            for (const item of data.list) {
                var subscribe = new DZModelSubscribe();
                subscribe.export = item.sExportName ?? '';
                subscribe.visitors = item.sVisitors ?? '';
                subscribe.phone = item.sVisPhone ?? '';
                subscribe.type = item.sType ?? '';
                subscribe.day = dateUtil.formatConversion(item.lDay ?? '');
                subscribe.time = item.sTime ?? '';
                subscribe.createTime = item.createTime ?? ''
                arr_data.push(subscribe);
            }
            this.list_subscribe = arr_data;
        })
    }

    net_export_page() {
        nyNetwork.down("导出当前预约列表", { ...this.m_subscribe_screen, ...this.m_page },'咨询列表');
    }

    net_export_all() {
        nyNetwork.down("导出全部预约列表", {},'咨询列表');
    }

    
    net_move_up(id, success: () => void) {
        nyNetwork.net("专家数据上移", { id: id }, data => {
            success();
        })
    }
    net_move_down(id, success: () => void) {
        nyNetwork.net("专家数据下移", { id: id }, data => {
            success();
        })
    }
    net_move_top(id, success: () => void) {
        nyNetwork.net("专家数据置顶", { id: id }, data => {
            success();
        })
    }
    net_cancel_top(id, success: () => void) {
        nyNetwork.net("专家取消置顶", { id: id }, data => {
            success();
        })
    }


}
export default DZServiceExport;